% This is hack to fix the lost tracks due to discrete beam movement.
% The correct fix, which will be required will be to revert to polar_noise2
% and then move the beam fluidly or only generate the detections when the
% beam is on boresight of the target. (Track updates occur at the same
% time).
function [cart, pol] = polar_noise3(pos_cart, sig_r, sig_az, origin, start_az, stop_az)

pos_sph = cart2pol(pos_cart, origin);
pos_shp_n(1) = pos_sph(1) + sig_r*randn(1,1);
pos_shp_n(2) = pos_sph(2) + sig_az*randn(1,1);

if (pos_shp_n(2) < start_az)
  pos_shp_n(2) = start_az;
elseif (pos_shp_n(2) > stop_az)
  pos_shp_n(2) = stop_az;
end

cart = pol2cart(pos_shp_n, origin);
pol  = pos_shp_n;